﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Icms.Core.Model;

namespace Icms.Core
{
    public class CaseKind
    {
        public Guid Id { get; set; }
        public string Code { get; set; }
        public int Index { get; set; }
    }

    public static class Const
    {
        public const string defendant = "01d41bcf-e0f7-432d-9595-2cbcdf105fbb";

        public static readonly IDictionary<Guid, string> languages = new Dictionary<Guid, string>
        {
            {new Guid("34D1F2D3-B216-DD11-AA1C-001E0B8014EB"),"Engleza" },
            {new Guid("58DC57DB-B216-DD11-AA1C-001E0B8014EB"),"Romana" },
            {new Guid("C4E138E3-B216-DD11-AA1C-001E0B8014EB"),"Rusa" },                                                                 
        };

        public static readonly IEnumerable<CaseKind> caseKinds = new List<CaseKind>
        {
            new CaseKind{Id = new Guid("E86F15B1-4C38-DD11-A568-001E0B8014EB"), Code = "Civil", Index = 1},
            new CaseKind{Id = new Guid("00E52DBB-4C38-DD11-A568-001E0B8014EB"), Code = "Criminal", Index = 2},
            new CaseKind{Id = new Guid("26F7FDD5-4C38-DD11-A568-001E0B8014EB"), Code = "Contraventional", Index = 3},
            new CaseKind{Id = new Guid("723F685A-DE45-DE11-8F43-002264FAFF6E"), Code = "Economic", Index = 4},
        };



        public static class PartiesCodes
        {
            public const string CivilPlantiff = "CIVIL_PLAINTIFF";
            public const string Appelant = "APPELANT";
            public const string Reviewer = "1__09";
            public const string CivilDefendant = "CIVIL_DEFENDANT";
            public const string VersusPartyCivil = "1__03";
            public const string CassationRequestSubmitterCivil = "Cassation_Request_Submitter";

            public const string PenalDefendant = "PENAL_DEFENDANT";
            public const string CassationRequestSubmitter = "Cassation Request Submitter";

            public const string Revizuient = "Revizuient";
            public const string VersusPartyPenal = "VersusParty";

            public const string VersusPartyConraventional = "3_01";
            public const string ContraventionalOffender = "CONTRAVENTIONAL_OFFENDER";

        }



        public static class CaseStatuses
        {
            public const string Entered = "Entered";
            public const string Registered = "Registered";
            public const string Examination = "Examination";
            public const string Assigned = "Assigned";
            public const string Incompleted = "Incompleted";
            public const string Returned = "Returned";
            public const string Refused = "Refused";
            public const string Appeal = "Appeal";
            public const string Enforcement = "Enforcement";
            public const string Archived = "Archived";
            public const string Completed = "Completed";
            public const string Merged = "Merged";
            public const string Suspended = "Suspended";
        }

    }



    public static class Extensions
    {
        public static object IfValIsThen(this object val, object isthis, object then)
        {
            return val == isthis ? then : val;
        }

        public static int CaseKind(this Guid id)
        {
            return Const.caseKinds.Where(o => o.Id.ToString().ToLower() == id.ToString().ToLower()).Single().Index;
        }

        public static Guid? CaseKind(this int o)
        {
            return Const.caseKinds.Where(v => v.Index == o).Single().Id;
        }

        public static IEnumerable<T> Pag<T>(this IEnumerable<T> collection, int page, int ps)
        {
            return collection.Skip((page - 1) * ps).Take(ps);
        }

        public static string GetPersonName(Person prs)
        {
            return string.Format("{0} {1}{2}", prs.LastName, prs.FirstName, !string.IsNullOrEmpty(prs.SurName) ? " " + prs.SurName : string.Empty);
        }

        public static string GetPersonAddress(Person prs)
        {
            return string.Format("{0}{1}{2}{3}", prs.Location,
                !string.IsNullOrEmpty(prs.Street) ? " str." + prs.Street : string.Empty,
                !string.IsNullOrEmpty(prs.Home) ? " c. " + prs.Home : string.Empty,
                !string.IsNullOrEmpty(prs.Appartment) ? " ap." + prs.Appartment : string.Empty);
        }


        public static string ReplaceQUOT(this string s)
        {
            return HttpUtility.HtmlDecode(s);
        }
    }
}